<?php
/************************************************************************
 Omnitrix - PHP Development Framework
 Copyright (C) 2012-2018 amonest(eastson@outlook.com)

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
************************************************************************/

$_XOPTIONS = array(
	'main_module' => 'admin',
);

require_once 'commons.php';

otx_import_functions('template', 'admin');
otx_language_load('module', 'admin', 'admin');



// if (isset($_SESSION['admin_id'])) {
// 	$sql = 'SELECT u.*, g.permissions AS group_permissions
// 			FROM #system_user# u
// 			LEFT JOIN #system_group# g ON g.group_id = u.group_id
// 			WHERE u.user_id = ?';
// 	$row = otx_db_fetch_row($sql, $_SESSION['admin_id']);
// 	if ($row && $row['status'] == 1) {
// 		$row['group_permissions'] = otx_string_unserialize($row['group_permissions']);
// 		otx_param_set('_admin_info', $row);
// 	}
// 	unset($sql, $row);
// } else {
// // 	if (otx_router_module() <> 'admin' || otx_router_controller() <> 'session') {
// // 		otx_router_redirect('login', 'session', 'admin');
// // 	}
// }

if (null === otx_session_user_id()) {
	if (otx_router_module() <> 'admin' || otx_router_controller() <> 'session') {
		otx_router_redirect('login', 'session', 'admin');
	}
}


otx_html_add_breadcrumb(otx_language_parse('text_dashboard'), 'admin.php');

//-----------------------------------------------------------------------
// 遍历所有已安装模块, 合并导航菜单到$_XNAVMENU
//-----------------------------------------------------------------------
// $_XNAVMENU = new omnitrix_tree();

// $module_names = otx_db_fetch_col('SELECT module_name FROM #system_module# ORDER BY module_id');
// foreach ($module_names as $module_name) {
// 	$module_instance = otx_module_instance($module_name);
// 	foreach ($module_instance->navmenu() as $navmenu_info) {
// 		// TODO
// 	}
// }




otx_router_execute();
$response_content = otx_param_string('_content'); //otx_theme_render();
if (otx_param_bool('is_ajax')) {
	otx_json_result($response_content);
} else {
	if (otx_param_bool('render_content')) {
		echo $response_content;
	} else {
		otx_html_response_output();
	}
}